package action.user;

import persistence.model.TdfkfaUser;
import service.UserService;
import util.StringUtil;

import com.opensymphony.xwork2.ActionSupport;

public class AddPlanUserAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private String userId;

	private String userPass;

	private String enabled;

	private TdfkfaUser planUser;

	private String saveStatus;

	private UserService userService;

	public String generatePlanUser() {

		userId = userService.generatePlanUserId();
		userPass = userService.generatePassword(8);
		return SUCCESS;
	}

	public String savePlanUser() {
		if (StringUtil.isEmpty(planUser.getUsername()) || StringUtil.isEmpty(planUser.getPassword())) {
			saveStatus = "error";
		} else {
			saveStatus = userService.savePlanUser(planUser);
		}
		return SUCCESS;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getUserPass() {
		return userPass;
	}

	public void setUserPass(String userPass) {
		this.userPass = userPass;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public String getEnabled() {
		return enabled;
	}

	public void setEnabled(String enabled) {
		this.enabled = enabled;
	}

	public String getSaveStatus() {
		return saveStatus;
	}

	public TdfkfaUser getPlanUser() {
		return planUser;
	}

	public void setPlanUser(TdfkfaUser planUser) {
		this.planUser = planUser;
	}

}
